// 公共搜索功能
document.addEventListener('DOMContentLoaded', function() {
	
    const searchInput = document.getElementById('searchInput');
    const searchButton = document.getElementById('searchButton');
    
    // 处理搜索跳转
    function handleSearch() {
        const keyword = searchInput.value.trim();
        if (keyword) {
            // 将搜索关键词通过URL参数传递到search.html
            window.location.href = `search.html?q=${encodeURIComponent(keyword)}`;
        } else {
            // 如果关键词为空，可以跳转到search.html并显示提示信息
            window.location.href = "search.html";
        }
    }
    
    // 点击搜索按钮
    if(searchButton) {
        searchButton.addEventListener('click', handleSearch);
    }
    
    // 回车键搜索
    if(searchInput) {
        searchInput.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                handleSearch();
            }
        });
    }
});